var deviceId;
var simplex = [
    {value: 'workActive', name: '总有功累计电量'},
    {value: 'workReacitive', name: '总无功累计电量'},
    {value: 'powerActive', name: '总有功功率'},
    {value: 'powerReacitive', name: '总无功功率'},
    {value: 'frequency', name: '电网频率'},
    {value: 'voltageA', name: '电压'},
    {value: 'currentA', name: '电流'},
    {value: 'powerFactorA', name: '功率因数'},
];
var threePhase = [
    {value: 'workActive', name: '总有功累计电量'},
    {value: 'workReacitive', name: '总无功累计电量'},
    {value: 'powerActive', name: '总有功功率'},
    {value: 'powerReacitive', name: '总无功功率'},
    {value: 'frequency', name: '电网频率'},
    {value: 'workActiveA', name: 'A相有功电量'},
    {value: 'workActiveB', name: 'B相有功电量'},
    {value: 'workActiveC', name: 'C相有功电量'},
    {value: 'workReacitiveA', name: 'A相无功电量'},
    {value: 'workReacitiveB', name: 'B相无功电量'},
    {value: 'workReacitiveC', name: 'C相无功电量'},
    {value: 'powerActiveA', name: 'A相有功功率'},
    {value: 'powerActiveB', name: 'B相有功功率'},
    {value: 'powerActiveC', name: 'C相有功功率'},
    {value: 'powerReacitiveA', name: 'A相无功功率'},
    {value: 'powerReacitiveB', name: 'B相无功功率'},
    {value: 'powerReacitiveC', name: 'C相无功功率'},
    {value: 'voltageA', name: 'A相电压'},
    {value: 'voltageB', name: 'B相电压'},
    {value: 'voltageC', name: 'C相电压'},
    {value: 'currentA', name: 'A相电流'},
    {value: 'currentB', name: 'B相电流'},
    {value: 'currentC', name: 'C相电流'},
    {value: 'powerFactorA', name: 'A相功率因数'},
    {value: 'powerFactorB', name: 'B相功率因数'},
    {value: 'powerFactorC', name: 'C相功率因数'},
];
$("#page").paging({
    pageNo: 0,
    totalPage: 0,
    totalSize: 0
});
$(function () {
    chartInit();//图表初始化
    deviceId = getQueryString('deviceId')
    getDeviceData();
    loadAlarmData();
    userInfo($('#userInfo'));
});

/*图表初始化*/
function chartInit() {
    chart_bar1.setOption(option_bar1);
    chart_line1.setOption(option_line1);
    chart_radar.setOption(option_radar);
    //“更多”弹窗中的图表配置与页面中一致，只是数据不同
    modalChart_time.setOption(option_bar1);
    modalChart_usage.setOption(option_line1);
    modalChart_history.setOption(option_line2);
    modalChart_history.setOption({
        grid: {
            left: 20,
            right: 35
        }
    });
    modalChart_electric.setOption(option_bar2_More);
    modalChart_electric.setOption({
        grid: {
            left: 20,
            right: 35
        },
        series: [{
            itemStyle: {
                normal: {
                    //不同时段柱子设置不同颜色
                    color: function (params) {
                        var colorList = [
                            "#009AEA",//谷 0-8
                            "#F2CB6B",//平 12-17，21-24
                            "#FF8B35"//峰 8-12，17-21
                        ];
                        if (Number(params.name.substr(6, 2)) >= 0 && Number(params.name.substr(6, 2)) < 8) {//谷
                            return colorList[0];
                        } else if ((Number(params.name.substr(6, 2)) >= 12 && Number(params.name.substr(6, 2)) < 17) || (Number(params.name.substr(6, 2)) >= 21)) {
                            return colorList[1];
                        } else {
                            return colorList[2]
                        }
                    }
                }
            }
        }]
    });
    modalChart_power.setOption(option_line3);
    modalChart_power.setOption({
        grid: {
            left: 20,
            right: 35
        }
    });
    modalChart_analysis.setOption(option_bar3);
}

/*谐波图表初始化*/
function harmonicChartInit() {
    chart_bar3 = echarts.init(document.getElementById('chart_bar3'));//电压谐波畸变率
    chart_bar4 = echarts.init(document.getElementById('chart_bar4'));//电流谐波畸变率
    chart_bar3.setOption(option_bar4);
    chart_bar4.setOption(option_bar4);
}

/*中间部分图表初始化*/
function middleChartInit() {
    chart_line2 = echarts.init(document.getElementById('chart_line2'));//历史数据
    chart_bar2 = echarts.init(document.getElementById('chart_bar2'));//今日用电量
    chart_line3 = echarts.init(document.getElementById('chart_line3'));//实时功率
    chart_line2.setOption(option_line2);
    chart_bar2.setOption(option_bar2);
    chart_line3.setOption(option_line3);
}


/*获取设备数据*/
function getDeviceData() {
    showLoading(LOADING);
    getJson("/deviceData/getProduceDeviceById", {"id": deviceId}, 'GET', function (result) {
        if (result.status == 200) {
            var data = result.data;
            VOData(data);
        } else {
            myAlert("提示", "加载设备数据失败");
        }
    })
}

/*渲染数据*/
function VOData(data) {
    $('#deviceName-id').html(data.name);
    $('#deviceSn-id').html(data.sn);
    if (!isNull(data.image)) {
        $('#image-id').attr('src', fileUrl + data.image);
        $('#image-id')[0].onerror = function () {//加载出错时，替换为默认图
            $(this).attr('src', '../customize/images/no-photo.png');
        }
    } else {//为空时，替换为默认图
        $('#image-id').attr('src', '../customize/images/no-photo.png');
    }
    $('#port_id').html(data.port);
    switch (data.status) {
        case 1:
            $('#status-div').addClass("text-powerOn");
            break;
        case 2:
            $('#status-div').addClass("text-standby");
            break;
        case 3:
            $('#status-div').addClass("text-powerOff");
            break;
        case 4:
            $('#status-div').addClass("text-fault");
            break;
        default:
            $('#status-div').addClass("text-standby");
            break;
    }
    //  查询当前设备关联的采集设备
    getJson("/deviceData/getDeviceByGroup", {"group": data.group}, 'GET', function (result) {
        $('#cj_name').html(result.name);
        $('#cj_bh').html(result.sn);
        switch (result.status) {
            case 1:
                $('#cj_status').addClass("text-powerOn");
                break;
            case 2:
                $('#cj_status').addClass("text-standby");
                break;
            case 3:
                $('#cj_status').addClass("text-powerOff");
                break;
            case 4:
                $('#cj_status').addClass("text-fault");
                break;
            default:
                $('#cj_status').addClass("text-standby");
                break;
        }
        getJson("/deviceData/getDeviceParamByClientID", {clientID: result['clientId']}, 'GET', function (result) {
            if (!isNull(result['payload']['data'])) {
                if (result['payload']['data'].harmonic && result['payload']['data'].harmonic > 0) {//谐波开启
                    simplex.push({value: 'distortionVA', name: '电压谐波畸变率'},
                        {value: 'distortionIA', name: '电流谐波畸变率'});
                    threePhase.push({value: 'distortionVA', name: 'A相电压谐波畸变率'},
                        {value: 'distortionVB', name: 'B相电压谐波畸变率'},
                        {value: 'distortionVC', name: 'C相电压谐波畸变率'},
                        {value: 'distortionIA', name: 'A相电流谐波畸变率'},
                        {value: 'distortionIB', name: 'B相电流谐波畸变率'},
                        {value: 'distortionIC', name: 'C相电流谐波畸变率'});
                    $('#hasnot_harmonic').remove();
                    $('#has_harmonic').css({
                        'maxWidth': '100%'
                    });
                    harmonicChartInit();
                    getJson("/deviceData/getDeviceHarmonicReal", {deviceId: deviceId}, 'GET', function (harmRes) {
                        var harmonicData = harmRes.payload.data;
                        if (isNull(harmonicData)) {
                            chartNoDataHint($('#chart_bar3'));
                            chartNoDataHint($('#chart_bar4'));
                        }
                        var vol_arr = [{
                            x: '总谐波',
                            A: harmonicData['distortionVA'],
                            B: harmonicData['distortionVB'],
                            C: harmonicData['distortionVC']
                        }];
                        var cur_arr = [{
                            x: '总谐波',
                            A: harmonicData['distortionIA'],
                            B: harmonicData['distortionIB'],
                            C: harmonicData['distortionIC']
                        }];
                        for (var i = 3; i < Number(result['payload']['data'].harmonic) + 1; i += 2) {//生成谐波次数+1长度的数组
                            vol_arr.push({
                                x: i + '次',
                                A: harmonicData['vah' + i],
                                B: harmonicData['vbh' + i],
                                C: harmonicData['vch' + i]
                            });
                            cur_arr.push({
                                x: i + '次',
                                A: harmonicData['iah' + i],
                                B: harmonicData['ibh' + i],
                                C: harmonicData['ich' + i]
                            });
                        }
                        if (data['powerSupply'] != 1) {//三相
                            chart_bar3.setOption({
                                dataset: {
                                    source: vol_arr
                                },
                                series: harmonic_multi
                            });
                            chart_bar4.setOption({
                                dataset: {
                                    source: cur_arr
                                },
                                series: harmonic_multi
                            });
                        } else {//单相
                            chart_bar3.setOption({
                                dataset: {
                                    source: vol_arr
                                },
                                series: harmonic_single
                            });
                            chart_bar4.setOption({
                                dataset: {
                                    source: cur_arr
                                },
                                series: harmonic_single
                            });
                        }

                    })
                } else {
                    $(".xbjb").remove();
                    $('#has_harmonic').remove();
                }
                if (data.powerSupply == 1) {//单相
                    buildSelectTwo($('#param_select'), simplex, 'name', 'value');
                    $('#wiring').text('单相制');
                    $('.three-phase').addClass('d-none');
                } else {
                    buildSelectTwo($('#param_select'), threePhase, 'name', 'value');
                    var wiring = '三相三线制';
                    if (result['payload']['data']['wiring'] == 1) {
                        wiring = '三相四线制';
                    }
                    $('#wiring').text(wiring);
                }
            } else {
                $(".xbjb").remove();
                $('#has_harmonic').remove();
                $('#wiring').text('三相四线制');
            }
            window.parent.changeIframeH();
            middleChartInit();
            loadHistoryData("workActive");
            //  查询当前设备今日用电量
            getJson("/deviceData/getTodayElectricity", {"id": data.id}, 'GET', function (result) {
                if (result.length == 0) {
                    chartNoDataHint($('#chart_bar2'));
                } else {
                    var xArray = new Array();
                    var yArray = new Array();
                    var ljdl = 0;
                    for (var j = 0; j < result.length; j++) {
                        xArray.push(result[j].date.substring(11, 16));
                        yArray.push(Math.round(result[j].str * 100) / 100);
                        ljdl += Number(result[j].str);
                    }
                    $('#ljdl_id').text(Math.round(ljdl * 100) / 100 + "kWh");
                    chart_bar2.setOption({//今日用电量柱状图
                        xAxis: {
                            data: xArray
                        },
                        series: [{
                            data: yArray,
                        }]
                    });
                }
            })
            //  获取实时功率
            getJson("/deviceData/getRealPower", {"id": data.id}, 'GET', function (result) {
                if (result.length == 0) {
                    chartNoDataHint($('#chart_line3'));
                } else {
                    var xArray = new Array();
                    var yArray = new Array();
                    for (var j = 0; j < result.length; j++) {
                        xArray.push(result[j].date.substring(11, 16));
                        yArray.push(Math.round(result[j].str * 10000) / 10000);
                    }
                    var option_line3 = {//实时功率折线图
                        xAxis: {
                            data: xArray
                        },
                        series: [{
                            data: yArray
                        }]
                    };
                    chart_line3.setOption(option_line3);
                }
            })
        })
    })
    /*查询关联生产设备的维保情况*/
    getJson("/maintenance/getMaintenanceInfoByDId", {"id": data.id}, 'GET', function (result) {
        $('#day_id').html(result.str + " 天");
        if (result.date) {
            $('#time_id').html(result.date.substring(0, 10));
        }
    })
    //  用电分析
    getJson("/deviceData/getElectricityAnalysisData", {"id": data.id}, 'GET', function (result) {
        if (!isNull(result)) {
            $('#jkzs_fs').html(Math.round(result['health'] * 10) / 10);
            var newArray = new Array();
            newArray.push(Math.round(result['voltageDeviation'] * 10) / 10);
            newArray.push(Math.round(result['frequencyDeviation'] * 10) / 10);
            if (data['powerSupply'] != 1) {
                newArray.push(Math.round(result['unblance'] * 10) / 10);
            }
            newArray.push(Math.round(result['loadRate'] * 10) / 10);
            newArray.push(Math.round(result['powerFactor'] * 10) / 10);
            $('#glys_id').html(Number(Number(result['powerFactor']).toFixed(2)));
            $('#fzl_id').html(Math.round(result['loadRate'] * 100) / 100);
            if (data['powerSupply'] == 1) {
                chart_radar.setOption({//用电分析
                    title: {
                        text: '单相电接入设备无三相不平衡数据'
                    },
                    radar: {
                        center: ['50%', '47%'],
                        radius: '60%',
                        indicator: [
                            {name: '电压偏差', max: 100},
                            {name: '频率\n偏差', max: 100},
                            {name: '负载率', max: 100},
                            {name: '功率\n因数', max: 100}
                        ],
                    },
                    series: [{
                        data: [{
                            value: newArray
                        }]

                    }]
                });
            } else {
                chart_radar.setOption({//用电分析
                    radar: {
                        indicator: [
                            {name: '电压偏差', max: 100},
                            {name: '频率\n偏差', max: 100},
                            {name: '三相不平衡', max: 100},
                            {name: '负载率', max: 100},
                            {name: '功率\n因数', max: 100}
                        ],
                    },
                    series: [{
                        data: [{
                            value: newArray
                        }]
                    }]
                });
            }
        }

        if (result.createTime) {
            $('#dataTime_id').html(result.createTime.substring(10));
        } else {
            $('#dataTime_id').html(result.createTime);
        }
        if (result.positionDeviation == 1) {
            $('#offset_id').empty();
            $('#offset_id').append(' <svg t="1592207529861" class="icon" viewBox="0 0 1732 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5180" width="44" height="26"><path d="M346.584615 187.076923h1039.753847c191.409231 0 346.584615 145.447385 346.584615 324.923077s-155.175385 324.923077-346.584615 324.923077H346.584615C155.175385 836.923077 0 691.475692 0 512s155.175385-324.923077 346.584615-324.923077z" fill="#CAE3FF" p-id="5181"></path><path d="M727.394462 512c0 277.661538 225.083077 502.784 502.784 502.784C1507.84 1014.784 1732.923077 789.661538 1732.923077 512S1507.84 9.255385 1230.178462 9.255385C952.516923 9.255385 727.394462 234.338462 727.394462 512z" fill="#2185F5" p-id="5182"></path></svg>');
        } else {
            $('#offset_id').empty();
            $('#offset_id').append(' <svg t="1598434215978" class="icon" viewBox="0 0 1764 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="29056" width="44" height="26"><path d="M352.951571 181.08849h1058.84962c194.925075 0 352.951571 148.118779 352.951571 330.891652s-158.025477 330.891652-352.951571 330.891652H352.951571C158.025477 842.871794 0 694.753015 0 511.980142s158.025477-330.891652 352.951571-330.891652z" fill="#7C89A6" p-id="29057"></path><path d="M0 511.980142c0 282.762494 229.217648 512.019858 512.019858 512.019858 282.762494 0 511.977087-229.257364 511.977087-512.019858S794.782352 0 512.021895 0 0 229.217648 0 511.980142z" fill="#D9DFE9" p-id="29058"></path></svg>');
        }
    })
    //  获取生产时长
    getJson("/deviceData/getProductionTime", {"id": data.id, "type": 0}, 'GET', function (result) {
            if (result.length == 0) {
                chartNoDataHint($('#chart_bar1'));
            } else {
                var xArray = new Array();
                var yArray = new Array();
                for (var j = 0; j < result.length; j++) {
                    if (result[j].date.substring(0, 10) == TimeNow().substring(0, 10)) {
                        $('#scsc_id').html(Math.round(result[j].str * 100) / 100 + 'h');
                    }
                    xArray.push(result[j].date.substring(5, 10));
                    yArray.push(Math.round(result[j].str * 100) / 100);
                }
                option_bar1 = {//生产时长柱状图
                    xAxis: {
                        data: xArray
                    },
                    series: [{
                        data: yArray
                    }]
                };
                chart_bar1.setOption(option_bar1);
            }
        }
    )
    //  获取设备使用率
    getJson("/deviceData/getDeviceUserate", {"id": data.id, "type": 2}, 'GET', function (result) {
            if (result.length == 0) {
                chartNoDataHint($('#chart_line1'));
            } else {
                var xArray = new Array();
                var yArray = new Array();
                var sum = 0;
                for (var j = 0; j < result.length; j++) {
                    xArray.push(result[j].createTime);
                    yArray.push(Math.round(result[j].usageRate * 100) / 100);
                    sum += Number(result[j].usageRate);
                }
                var avg = Number(sum / 7);
                $('#syl_value_id').html(Math.round(avg * 100) / 100 + "%");
                $('#syl_id').width(avg + "%");
                chart_line1.setOption({//设备使用率折线图
                    xAxis: {
                        data: xArray
                    },
                    series: [{
                        data: yArray
                    }]
                });
            }
        }
    )
    loadPowerConsumptionStatistics();
}

/*加载设备历史数据*/
function loadHistoryData(param) {
    loadHistory(param, $('#chart_line2'), chart_line2);
}

var harmonic_markLine = {
    silent: true,
    symbol: 'none',
    lineStyle: {
        color: '#fff'
    },
    data: [{
        yAxis: 5
    }],
    label: {
        position: 'insideEndBottom',
        formatter: '国际限值{c}%'
    }
};

/*加载历史数据*/
function loadHistory(param, dom, chart, bDate, eDate, type) {
    if (oneMonthLimit(bDate, eDate)) {
        showModalHint("none", "请将时间范围控制在30天内");
        return;
    }
    if (!type) {
        type = 1;
    }
    showLoading(LOADING);
    chartNoDataHintHide(dom);
    getJson("/historyData/getHistoryDataByParam", {
        "param": param,
        "dId": deviceId,
        "beginDate": bDate,
        "endDate": eDate,
        "type": type
    }, 'GET', function (result) {
        var xArray = new Array();
        var yArray = new Array();
        var data = result.data;
        var name;
        var markLine = null;
        var yMin = null;
        switch (result.param) {
            case "workActive":
                name = "总有功累计电量";
                break;
            case "workReacitive":
                name = "总无功累计电量";
                break;
            case "powerActive":
                name = "总有功功率";
                break;
            case "powerReacitive":
                name = "总无功功率";
                break;
            case "frequency":
                name = "电网频率";
                break;
            case "workActiveA":
            case "workActiveB":
            case "workActiveC":
                name = "有功电量";
                break;
            case "workReacitiveA":
            case "workReacitiveB":
            case "workReacitiveC":
                name = "无功电量";
                break;
            case "powerActiveA":
            case "powerActiveB":
            case "powerActiveC":
                name = "有功功率";
                break;
            case "powerReacitiveA":
            case "powerReacitiveB":
            case "powerReacitiveC":
                name = "无功功率";
                break;
            case "voltageA":
            case "voltageB":
            case "voltageC":
                name = "电压";
                break;
            case "currentA":
            case "currentB":
            case "currentC":
                name = "电流";
                break;
            case "powerFactorA":
            case "powerFactorB":
            case "powerFactorC":
                name = "功率因数";
                break;
            case "distortionVA":
            case "distortionVB":
            case "distortionVC":
                name = "电压谐波畸变率";
                markLine = harmonic_markLine;
                yMin = function (value) {
                    return value.max < 5 ? 5 : null;
                };
                break;
            case "distortionIA":
            case "distortionIB":
            case "distortionIC":
                name = "电流谐波畸变率";
                break;
        }
        if (!data || data.length == 0) {
            chartNoDataHint(dom);
        }
        var leng = data ? data.length : 0;
        for (var i = 0; i < leng; i++) {
            if (type == 2) {
                xArray.push(data[i].date.substr(5, 11));
            } else {
                xArray.push(data[i].date.substring(11, 16));
            }
            yArray.push(Math.round(data[i].str * 100) / 100);
        }
        chart.setOption({//折线图
            xAxis: {
                data: xArray
            },
            yAxis: {
                max: yMin
            },
            series: [{
                name: name,//选择参数时，设置为相应参数名
                data: yArray,
                markLine: markLine
            }]
        });

        hideLoading();
    })
}

/*加载历史报警数据*/
var title = ['#', '告警等级', '设备', '告警内容', '告警时间', '处理状态', '处理结果'];
var label = ['order', 'grade', 'name', 'content', 'createtime', 'status', 'result'];

function loadAlarmData() {
    $('#alarm_List tbody').empty();
    getJson("/alarm/findAlarmByParamsTop10", {"dId": deviceId}, 'GET', function (result) {
        var tr = '';
        for (var i = 1; i < result.data.length + 1; i++) {
            var data = result.data[i - 1];
            var alarmStatus;
            var statusType = data.status == 1 ? ' <td class="text-danger">未处理</td>' : data.status == 2 ? ' <td class="text-warning">未恢复</td>' : '<td>已恢复</td>';
            // let res = data.result==null?'':data.result;
            switch (data.grade) {
                case 1:
                    alarmStatus = ' <td class="alarm-level level1">普通</td>';
                    break;
                case 2:
                    alarmStatus = ' <td class="alarm-level level2">一般</td>';
                    break;
                case 3:
                    alarmStatus = ' <td class="alarm-level level3">严重</td>';
                    break;
                case 4:
                    alarmStatus = '<td class="alarm-level level4">故障</td>';
                    break;
            }
            tr += '<tr>' +
                alarmStatus +
                '<td>' + data.content + '</td>\n' +
                '<td>' + data.createtime + '</td>\n' +
                statusType +
                '</tr>';
        }
        $('#alarm_List tbody').append(tr);
        if (result.data.length < 1) {
            $('#alarm_List tbody').empty();
            $("#alarm_List tbody").append("<tr><td align='center' colspan='4'>无报警数据</td></tr>");
        }
    })
}

/*加载用电统计*/
function loadPowerConsumptionStatistics() {
    getJson("/deviceData/getProduceDeviceById", {"id": deviceId}, 'GET', function (res) {
        var data = res.data;
        var currentPrice = Number(0);
        var time = new Date().getHours();
        if (judgeThePeakValleyFlat(time) == 'max') {
            currentPrice = data.maxPrice;
        } else if (judgeThePeakValleyFlat(time) == 'min') {
            currentPrice = data.minPrice;
        } else {
            currentPrice = data.avgPrice;
        }
        getJson("/deviceData/getPowerConsumptionStatistics/", {"id": deviceId}, 'GET', function (result) {
            $("#thisMonth_id").html(Math.round(result.ebtm) / 10000);
            $("#today_id").html(Math.round(result.electricityCharge) / 10000);
            $("#yesterday_id").html(Math.round(result.yeb) / 10000);
            $('#ssyg_id').html(Math.round(result.realActive * 10000) / 10000);
            $('#sswg_id').html(Math.round(result.realReactive * 10000) / 10000);
            $('#currentPrice').html(Math.round(currentPrice * 10000) / 10000);
            $('#yesterdayPrice').html(Math.round(result.dailyPrice * 10000) / 10000);
            $('#lastMonthPrice').html(Math.round(result.eplm * 10000) / 10000);
            hideLoading();
        })
    })
}

/*用电量、功率、历史切换*/
$('#switch_sec .btn').click(function () {
    var index = $(this).index();
    $(this).addClass('btn-primary').removeClass('btn-inactive');
    $(this).siblings().addClass('btn-inactive').removeClass('btn-primary');
    $('.nav-tab-sec').addClass('d-none');
    $('.nav-tab-sec' + index).removeClass('d-none');
    chart_bar2.resize();
    chart_line3.resize();
    chart_line2.resize();
});

/* 点击更多按钮 */
function viewMore(para) {
    $('#viewMoreModal_' + para).modal();
    switch (para) {//根据参数加载图表数据
        case 'history'://历史数据
            $('#searchTimeBegin_history').val('');
            $('#searchTimeEnd_history').val('');
            loadMoreHistoryData("workActive", "2");
            break;
        case 'time'://生产时长
            $('#searchTimeBegin_time').val('');
            $('#searchTimeEnd_time').val('');
            loadProductionTimeData('', '');
            break;
        case 'usage'://设备使用率
            $('#searchTimeBegin_usage').val('');
            $('#searchTimeEnd_usage').val('');
            loadEquipmentUsage('', '');
            break;
        case 'electric'://用电量
            $('#searchTimeBegin_electric').val('');
            $('#searchTimeEnd_electric').val('');
            loadTodayElectricityData('', '');
            break;
        case 'power'://功率
            $('#searchTimeBegin_power').val('');
            $('#searchTimeEnd_power').val('');
            loadRealPowerData('', '');
            break;
        case 'analysis'://用电分析
            $('#searchTimeBegin_analysis').val('');
            $('#searchTimeEnd_analysis').val('');
            loadElectricityAnalysisData('', '');
            break;
        case 'harmonic_v'://电压谐波畸变率
            $('#searchTimeBegin_harmonic_v').val('');
            $('#searchTimeEnd_harmonic_v').val('');
            break;
        case 'harmonic_c'://电流谐波畸变率
            $('#searchTimeBegin_harmonic_c').val('');
            $('#searchTimeEnd_harmonic_c').val('');
            break;
        case 'alarm':
            $('#searchTimeBegin_alarm').val('');
            $('#searchTimeEnd_alarm').val('');
            loadMoreAlarmData();
            break;
    }
    //图表resize
    if (para != 'alarm') {
        $('#viewMoreModal_' + para).on('shown.bs.modal', function (e) {
            eval('modalChart_' + para).resize();
            chartNoDataHintResize($('#modalChart_' + para));
        })
    }
}

/*更多-生产时长*/
function loadProductionTimeData(beginTime, endTime) {
    showLoading(LOADING);
    getJson("/deviceData/getProductionTime", {
        "id": deviceId,
        "beginTime": beginTime,
        "endTime": endTime,
        "type": 1
    }, 'GET', function (result) {
        if (result.length == 0) {
            chartNoDataHint($('#modalChart_time'));
            hideLoading();
        } else {
            chartNoDataHintHide($('#modalChart_time'));
        }
        var xArray = new Array();
        var yArray = new Array();
        for (var j = 0; j < result.length; j++) {
            xArray.push(result[j].date.substring(5, 10));
            yArray.push(Math.round(result[j].str * 100) / 100);
        }
        modalChart_time.setOption({//生产时长柱状图
            xAxis: {
                data: xArray
            },
            series: [{
                data: yArray
            }]
        });
        hideLoading();
    })
}

/*更多-设备使用率*/
function loadEquipmentUsage(beginTime, endTime) {
    showLoading(LOADING);
    //  获取设备使用率
    getJson("/deviceData/getDeviceUserate", {
        "id": deviceId,
        "beginTime": beginTime,
        "endTime": endTime,
        "type": 1
    }, 'GET', function (result) {
        if (result.length == 0) {
            chartNoDataHint($('#modalChart_usage'));
            hideLoading();
        } else {
            chartNoDataHintHide($('#modalChart_usage'));
        }
        var xArray = new Array();
        var yArray = new Array();
        for (var j = 0; j < result.length; j++) {
            xArray.push(result[j].createTime);
            yArray.push(result[j].usageRate);
        }
        modalChart_usage.setOption({//设备使用率折线图
            xAxis: {
                data: xArray
            },
            series: [{
                data: yArray
            }]
        });
        hideLoading();
    })
}

/*更多-设备历史数据*/
function loadMoreHistoryData(param, type) {
    if (!param) {
        param = $('input[name="param"]:checked').val();
    }
    type = 2
    loadHistory(param, $('#modalChart_history'), modalChart_history, $('#searchTimeBegin_history').val(), $('#searchTimeEnd_history').val(), type);
}

//更多-用电量
function loadTodayElectricityData(beginTime, endTime) {
    if (oneMonthLimit(beginTime, endTime)) {
        showModalHint("none", "请将时间范围控制在30天内");
        return;
    }
    showLoading(LOADING);
//  根据条件查询用电量
    getJson("/deviceData/getTodayElectricityByParam", {
            "id": deviceId,
            "beginTime": beginTime,
            "endTime": endTime
        }, 'GET', function (result) {
            if (result.length == 0) {
                chartNoDataHint($('#modalChart_electric'));
                hideLoading();
            } else {
                chartNoDataHintHide($('#modalChart_electric'));
            }
            getJson("/deviceData/getDeviceByDid", {id: deviceId}, 'GET', function (device) {
                var xArray = new Array();
                var yArray = new Array();
                var maxCount = 0;
                var minCount = 0;
                var avgCount = 0;
                for (var j = 0; j < result.length; j++) {
                    switch (judgeThePeakValleyFlat(result[j].date.substr(11, 5))) {
                        case 'min':
                            minCount += Number(result[j].str);
                            break;
                        case 'avg':
                            avgCount += Number(result[j].str);
                            break;
                        case 'max':
                            maxCount += Number(result[j].str);
                            break;
                    }
                    xArray.push(result[j].date.substr(5, 11));
                    yArray.push(result[j].str);
                }
                var count = maxCount * device['maxPrice'] + minCount * device['minPrice'] + avgCount * device['avgPrice'];
                $('#ljdlgd_id').text(Math.round((maxCount + minCount + avgCount) * 100) / 100 + 'kWh');
                $('#ygdf_id').text(Math.round(count) / 10000);
                modalChart_electric.setOption({//今日用电量柱状图
                    xAxis: {
                        data: xArray
                    },
                    series: [{
                        data: yArray
                    }]
                });
                hideLoading();
            });
        }
    )
}

//更多-功率
function loadRealPowerData(beginTime, endTime) {
    if (oneMonthLimit(beginTime, endTime)) {
        showModalHint("none", "请将时间范围控制在30天内");
        return;
    }
    showLoading(LOADING);
    //  获取更多功率
    getJson("/deviceData/getRealPowerParam", {
            "id": deviceId,
            "beginTime": beginTime,
            "endTime": endTime
        }, 'GET', function (result) {
            if (result.length == 0) {
                chartNoDataHint($('#modalChart_power'));
                hideLoading();
            } else {
                chartNoDataHintHide($('#modalChart_power'));
            }
            var xArray = new Array();
            var yArray = new Array();
            for (var j = 0; j < result.length; j++) {
                xArray.push(result[j].date.substr(5, 11));
                yArray.push(Math.round(result[j].str * 10000) / 10000);
            }
            modalChart_power.setOption({//实时功率折线图
                xAxis: {
                    data: xArray
                },
                series: [{
                    data: yArray
                }]
            });
            hideLoading();
        }
    )
}

/*更多-用电分析*/
function loadElectricityAnalysisData(beginTime, endTime) {
    if (oneMonthLimit(beginTime, endTime)) {
        showModalHint("none", "请将时间范围控制在30天内");
        return;
    }
    showLoading(LOADING);
    getJson("/deviceData/getElectricityAnalysisDataByParam", {
        "id": deviceId,
        "beginTime": beginTime,
        "endTime": endTime
    }, 'GET', function (result) {
        if (result.length == 0) {
            chartNoDataHint($('#modalChart_analysis'));
            hideLoading();
        } else {
            chartNoDataHintHide($('#modalChart_analysis'));
        }
        //电压偏差
        var voltageDeviationArray = new Array();
        //频率偏差
        var frequencyDeviationArray = new Array();
        //三相不平衡
        var unblanceArray = new Array();
        //负载率
        var loadRateArray = new Array();
        //健康指数
        var healthArray = new Array();
        //功率因数
        var powerFactor = new Array();
        //X轴时间
        var timeArray = new Array();
        for (var i = 0; i < result.length; i++) {
            voltageDeviationArray.push(Math.round(result[i].voltageDeviation * 100) / 100);
            frequencyDeviationArray.push(Math.round(result[i].frequencyDeviation * 100) / 100);
            unblanceArray.push(Math.round(result[i].unblance * 100) / 100);
            loadRateArray.push(Math.round(result[i].loadRate * 100) / 100);
            healthArray.push(Math.round(result[i].health * 10) / 10);
            powerFactor.push(Math.round(result[i].powerFactor * 100) / 100);
            timeArray.push(result[i].createTime);
        }
        option_bar3 = {//用电分析柱状/折线图
            dataZoom: [{
                startValue: timeArray.length - 7,
                endValue: timeArray.length - 1,
            }],
            xAxis: {
                data: timeArray
            },
            series: [{
                data: voltageDeviationArray
            }, {
                data: powerFactor
            }, {
                data: frequencyDeviationArray
            }, {
                data: unblanceArray
            }, {
                data: loadRateArray
            }, {
                data: healthArray
            }]
        };
        modalChart_analysis.setOption(option_bar3);
        hideLoading();
    })
}

/*更多-历史报警*/
function loadMoreAlarmData(_pageIndex) {
    if (oneMonthLimit($('#searchTimeBegin_alarm').val(), $('#searchTimeEnd_alarm').val())) {
        showModalHint('none', "请将时间范围控制在30天内");
        return;
    }
    var pageIndex = parseInt(_pageIndex ? _pageIndex : '1');
    showLoading(LOADING);
    $('#alarm_MoreList tbody').empty();
    getJson("/alarm/findAlarmByParams", {
        "dId": deviceId,
        "beginTime": $('#searchTimeBegin_alarm').val(),
        "endTime": $('#searchTimeEnd_alarm').val(),
        "status": $('#status-id').val(),
        pageIndex: pageIndex,
        pageSize: 5
    }, 'GET', function (result) {
        if (result['code'] == 200) {
            var data = result['payload']['data'];
            setPage($('#page'), pageIndex, result['payload']['pages'], result['payload']['total'], function (num) {
                loadMoreAlarmData(num);
            });
            var order = 1 + 10 * (pageIndex - 1);
            data.map(function (item) {
                item['order'] = order++;
            });
            buildTable($('#alarm_MoreList'), title, label, data, function (td, label, item) {
                switch (label) {
                    case 'grade':
                        $(td).empty();
                        var sp = createElement('span', td);
                        switch (item['grade']) {
                            case 1:
                                $(sp).addClass('badge').addClass('level1');
                                $(sp).text('普通');
                                break;
                            case 2:
                                $(sp).addClass('badge').addClass('level2');
                                $(sp).text('一般');
                                break;
                            case 3:
                                $(sp).addClass('badge').addClass('level3');
                                $(sp).text('严重');
                                break;
                            case 4:
                                $(sp).addClass('badge').addClass('level4');
                                $(sp).text('故障');
                                break;
                        }
                        break;
                    case 'status':
                        $(td).empty();
                        if (item['status'] == 1) {
                            $(td).addClass('text-danger');
                            $(td).text('未处理');
                        } else if (item['status'] == 2) {
                            $(td).addClass('text-warning');
                            $(td).text('未恢复');
                        } else if (item['status'] == 3) {
                            $(td).text('已恢复');
                        }
                        break;
                    case 'result':
                        $(td).empty();
                        $(td).text(item['result'] == null ? '' : item['result']);
                        break;
                }
            })
        }
        /* let tr = '';
         for (let i = 1; i < result.data.length + 1; i++) {
             let data = result.data[i - 1];
             let alarmStatus;
             let statusType = data.status == 1 ? ' <td class="text-danger">未处理</td>' : data.status == 2 ? ' <td class="text-warning">未恢复</td>' : '<td>已恢复</td>';
             let res = data.result == null ? '' : data.result;
             switch (data.grade) {
                 case 1:
                     alarmStatus = '<td><span class="badge level1">普通</span></td>';
                     break;
                 case 2:
                     alarmStatus = '<td><span class="badge level2">一般</span></td>';
                     break;
                 case 3:
                     alarmStatus = '<td><span class="badge level3">严重</span></td>';
                     break;
                 case 4:
                     alarmStatus = '<td><span class="badge level4">故障</span></td>';
                     break;
             }
             tr += '<tr id=tr_' + i + '>' +
                 '<td>' + i + '</td>\n' +
                 alarmStatus +
                 '<td>' + data.name + '</td>\n' +
                 '<td>' + data.content + '</td>\n' +
                 '<td>' + data.createtime + '</td>\n' +
                 statusType +
                 '<td>' + res + '</td>' +
                 '</tr>';
         }
         $('#alarm_MoreList tbody').append(tr);
         set_pagingTo(result.data.length);*/
        hideLoading();
    })
}

// 设置显示的行
function set_trTo(e) {
    var start = (e - 1) * 5 + 1;
    var end = e * 5;
    $('#alarm_MoreList tbody tr').addClass('d-none');
    for (var i = start; i <= end; i++) { // tr_len是要控制的tr个数
        $("#tr_" + i).removeClass('d-none');
    }
}

/* 设置分页，条件：分页组件id：page，表格id：data_table，每页展示10行 */
function set_pagingTo(e) {
    $("#page").paging({
        pageNo: 1,
        totalPage: Math.ceil(e / 5),
        totalSize: e,
        callback: function (num) {
            set_trTo(num);
        }
    });
    set_trTo(1);
    if (e < 1) {
        $('#alarm_MoreList tbody').empty();
        $("#alarm_MoreList tbody").append($("<tr><td align='center' colspan='15'>选择条件内无数据</td></tr>"));
    }
}

laydate.render({
    elem: '#searchTimeBegin_time'
});
laydate.render({
    elem: '#searchTimeEnd_time'
});
laydate.render({
    elem: '#searchTimeBegin_usage'
});
laydate.render({
    elem: '#searchTimeEnd_usage'
});
laydate.render({
    elem: '#searchTimeBegin_history',
    type: 'datetime',
});
laydate.render({
    elem: '#searchTimeEnd_history',
    type: 'datetime'
});
laydate.render({
    elem: '#searchTimeBegin_electric',
    type: 'datetime'
});
laydate.render({
    elem: '#searchTimeEnd_electric',
    type: 'datetime'
});
laydate.render({
    elem: '#searchTimeBegin_power',
    type: 'datetime'
});
laydate.render({
    elem: '#searchTimeEnd_power',
    type: 'datetime'
});
laydate.render({
    elem: '#searchTimeBegin_alarm',
    type: 'datetime'
});
laydate.render({
    elem: '#searchTimeEnd_alarm',
    type: 'datetime'
});
laydate.render({
    elem: '#searchTimeBegin_harmonic_v',
    type: 'datetime'
});
laydate.render({
    elem: '#searchTimeEnd_harmonic_v',
    type: 'datetime'
});
laydate.render({
    elem: '#searchTimeBegin_harmonic_c',
    type: 'datetime'
});
laydate.render({
    elem: '#searchTimeEnd_harmonic_c',
    type: 'datetime'
});
laydate.render({
    elem: '#searchTimeBegin_analysis',
    type: 'datetime'
});
laydate.render({
    elem: '#searchTimeEnd_analysis',
    type: 'datetime'
});

var chart_bar1 = echarts.init(document.getElementById('chart_bar1'));//生产时长
var chart_line1 = echarts.init(document.getElementById('chart_line1'));//设备使用率
var chart_line2;//历史数据
var chart_bar2;//今日用电量
var chart_line3;//实时功率
var chart_radar = echarts.init(document.getElementById('chart_radar'));//用电分析
var modalChart_time = echarts.init(document.getElementById('modalChart_time'));//modal图表-生产时长
var modalChart_usage = echarts.init(document.getElementById('modalChart_usage'));//modal图表-设备使用率
var modalChart_history = echarts.init(document.getElementById('modalChart_history'));//modal图表-历史数据
var modalChart_electric = echarts.init(document.getElementById('modalChart_electric'));//modal图表-用电量
var modalChart_power = echarts.init(document.getElementById('modalChart_power'));//modal图表-实时功率
var modalChart_analysis = echarts.init(document.getElementById('modalChart_analysis'));//modal图表-用电分析
var chart_bar3;//电压谐波畸变率
var chart_bar4;//电流谐波畸变率

var timeArr = increaseTime();
var arrLength = timeArr.length;

var option_bar1 = {//生产时长
    tooltip: {
        trigger: 'axis',
        axisPointer: {
            type: 'shadow',
            shadowStyle: {
                color: 'rgba(59, 85, 159, 0.3)'
            }
        },
        backgroundColor: 'rgba(39, 71, 105, 0.7)'
    },
    grid: {
        top: 10,
        left: 0,
        right: 0,
        bottom: 0,
        containLabel: true
    },
    xAxis: {
        type: 'category',
        axisLine: {
            lineStyle: {
                color: 'rgba(209, 230, 249, 0.7)'
            }
        },
        axisLabel: {
            color: 'rgba(209, 230, 249, 0.7)'
        },
        axisTick: {
            lineStyle: {
                color: 'rgba(209, 230, 249, 0.7)'
            }
        },
        splitLine: {
            show: false
        }
    },
    yAxis: {
        type: 'value',
        axisLine: {
            show: false
        },
        axisLabel: {
            color: '#fff'
        },
        axisTick: {
            show: false
        },
        splitLine: {
            lineStyle: {
                color: ['rgba(22, 126, 226, 0.2)'],
                type: 'dashed'
            }
        }
    },
    series: [{
        name: '生产时长',
        type: 'bar',
        itemStyle: {
            color: new echarts.graphic.LinearGradient(
                0, 0, 0, 1,
                [
                    {offset: 0, color: '#00E3D2'},
                    {offset: 1, color: 'rgba(0,0,0,0)'}
                ]
            )
        },
    }]
};
var option_line1 = {//设备使用率
    color: '#01E2D3',
    tooltip: {
        trigger: 'axis',
        axisPointer: {
            type: 'line',
            lineStyle: {
                type: 'dashed',
                color: '#FAD488'
            }
        }
    },
    grid: {
        top: 15,
        left: 10,
        right: 10,
        bottom: 0,
        containLabel: true
    },
    xAxis: {
        type: 'category',
        axisLine: {
            lineStyle: {
                color: 'rgba(209, 230, 249, 0.7)'
            }
        },
        axisLabel: {
            color: 'rgba(209, 230, 249, 0.7)'
        },
        axisTick: {
            lineStyle: {
                color: 'rgba(209, 230, 249, 0.7)'
            }
        },
        splitLine: {
            show: false
        }
    },
    yAxis: {
        type: 'value',
        axisLine: {
            show: false
        },
        axisLabel: {
            color: '#fff'
        },
        axisTick: {
            show: false
        },
        splitLine: {
            lineStyle: {
                color: ['rgba(22, 126, 226, 0.2)'],
                type: 'dashed'
            }
        }
    },
    series: [{
        name: '设备使用率',
        type: 'line',
        symbolSize: 5,
        lineStyle: {
            width: 2
        }
    }]
};
var option_line2 = {//历史数据
    color: '#C6F694',
    tooltip: {
        trigger: 'axis',
        axisPointer: {
            type: 'line',
            lineStyle: {
                color: '#C6F694'
            }
        },
        backgroundColor: 'rgba(39, 71, 105, 0.7)'
    },
    grid: {
        top: 15,
        left: 15,
        right: 18,
        bottom: 0,
        containLabel: true
    },
    xAxis: {
        type: 'category',
        boundaryGap: false,
        axisLine: {
            lineStyle: {
                color: 'rgba(209, 230, 249, 0.7)'
            }
        },
        axisLabel: {
            color: 'rgba(209, 230, 249, 0.7)'
        },
        axisTick: {
            lineStyle: {
                color: 'rgba(209, 230, 249, 0.7)'
            }
        },
        splitLine: {
            show: false
        }
    },
    yAxis: {
        type: 'value',
        axisLine: {
            show: false
        },
        axisLabel: {
            color: '#fff'
        },
        axisTick: {
            show: false
        },
        splitLine: {
            lineStyle: {
                color: ['rgba(22, 126, 226, 0.2)'],
                type: 'dashed'
            }
        }
    },
    series: [{
        name: '功率',
        type: 'line',
        showSymbol: false,
        lineStyle: {
            width: 2
        },
        areaStyle: {
            color: {
                type: 'linear',
                x: 0,
                y: 0,
                x2: 0,
                y2: 1,
                colorStops: [{
                    offset: 0, color: 'rgba(174,245,156,0.31)'
                }, {
                    offset: 1, color: 'rgba(254,248,128,0)'
                }]
            }
        }
    }]
};
var option_bar2 = {//今日用电量
    tooltip: {
        trigger: 'axis',
        axisPointer: {
            type: 'shadow',
            shadowStyle: {
                color: 'rgba(59, 85, 159, 0.3)'
            }
        },
        backgroundColor: 'rgba(39, 71, 105, 0.7)'
    },
    grid: {
        top: 10,
        left: 15,
        right: 18,
        bottom: 0,
        containLabel: true
    },
    xAxis: {
        type: 'category',
        axisLine: {
            lineStyle: {
                color: 'rgba(209, 230, 249, 0.7)'
            }
        },
        axisLabel: {
            color: 'rgba(209, 230, 249, 0.7)'
        },
        axisTick: {
            lineStyle: {
                color: 'rgba(209, 230, 249, 0.7)'
            }
        },
        splitLine: {
            show: false
        }
    },
    yAxis: {
        type: 'value',
        axisLine: {
            show: false
        },
        axisLabel: {
            color: '#fff'
        },
        axisTick: {
            show: false
        },
        splitLine: {
            lineStyle: {
                color: ['rgba(22, 126, 226, 0.2)'],
                type: 'dashed'
            }
        }
    },
    series: [{
        name: '用电量',
        type: 'bar',
        barMaxWidth: 6,
        itemStyle: {
            normal: {
                barBorderRadius: [3, 3, 0, 0],
                //不同时段柱子设置不同颜色
                color: function (params) {
                    var colorList = [{//谷 0-8
                        type: 'linear',
                        x: 0,
                        y: 0,
                        x2: 0,
                        y2: 1,
                        colorStops: [{
                            offset: 0, color: '#009AEA' // 0% 处的颜色
                        }, {
                            offset: 1, color: 'rgba(0,154,234,0)' // 100% 处的颜色
                        }],
                        global: false // 缺省为 false
                    }, {//平 12-17，21-24
                        type: 'linear',
                        x: 0,
                        y: 0,
                        x2: 0,
                        y2: 1,
                        colorStops: [{
                            offset: 0, color: '#F2CB6B' // 0% 处的颜色
                        }, {
                            offset: 1, color: 'rgba(242,203,107,0)' // 100% 处的颜色
                        }],
                        global: false // 缺省为 false
                    }, {//峰 8-12，17-21
                        type: 'linear',
                        x: 0,
                        y: 0,
                        x2: 0,
                        y2: 1,
                        colorStops: [{
                            offset: 0, color: '#FF8B35' // 0% 处的颜色
                        }, {
                            offset: 1, color: 'rgba(255,139,53,0)' // 100% 处的颜色
                        }],
                        global: false // 缺省为 false
                    }];
                    if (Number(params.name.substr(0, 2)) >= 0 && Number(params.name.substr(0, 2)) < 8) {//谷
                        return colorList[0];
                    } else if ((Number(params.name.substr(0, 2)) >= 12 && Number(params.name.substr(0, 2)) < 17) || (Number(params.name.substr(0, 2)) >= 21)) {
                        return colorList[1];
                    } else {
                        return colorList[2]
                    }
                }
            }
        }
    }]
};
var option_bar2_More = {//今日用电量更多
    tooltip: {
        trigger: 'axis',
        axisPointer: {
            type: 'shadow',
            shadowStyle: {
                color: 'rgba(59, 85, 159, 0.3)'
            }
        },
        backgroundColor: 'rgba(39, 71, 105, 0.7)'
    },
    grid: {
        top: 10,
        left: 15,
        right: 18,
        bottom: 0,
        containLabel: true
    },
    xAxis: {
        type: 'category',
        axisLine: {
            lineStyle: {
                color: 'rgba(209, 230, 249, 0.7)'
            }
        },
        axisLabel: {
            color: 'rgba(209, 230, 249, 0.7)'
        },
        axisTick: {
            lineStyle: {
                color: 'rgba(209, 230, 249, 0.7)'
            }
        },
        splitLine: {
            show: false
        }
    },
    yAxis: {
        type: 'value',
        axisLine: {
            show: false
        },
        axisLabel: {
            color: '#fff'
        },
        axisTick: {
            show: false
        },
        splitLine: {
            lineStyle: {
                color: ['rgba(22, 126, 226, 0.2)'],
                type: 'dashed'
            }
        }
    },
    series: [{
        name: '用电量',
        type: 'bar',
        barMaxWidth: 6,
        itemStyle: {
            normal: {
                barBorderRadius: [3, 3, 0, 0],
                //不同时段柱子设置不同颜色
                color: function (params) {
                    var colorList = [{//谷 0-8
                        type: 'linear',
                        x: 0,
                        y: 0,
                        x2: 0,
                        y2: 1,
                        colorStops: [{
                            offset: 0, color: '#009AEA' // 0% 处的颜色
                        }, {
                            offset: 1, color: 'rgba(0,154,234,0)' // 100% 处的颜色
                        }],
                        global: false // 缺省为 false
                    }, {//平 12-17，21-24
                        type: 'linear',
                        x: 0,
                        y: 0,
                        x2: 0,
                        y2: 1,
                        colorStops: [{
                            offset: 0, color: '#F2CB6B' // 0% 处的颜色
                        }, {
                            offset: 1, color: 'rgba(242,203,107,0)' // 100% 处的颜色
                        }],
                        global: false // 缺省为 false
                    }, {//峰 8-12，17-21
                        type: 'linear',
                        x: 0,
                        y: 0,
                        x2: 0,
                        y2: 1,
                        colorStops: [{
                            offset: 0, color: '#FF8B35' // 0% 处的颜色
                        }, {
                            offset: 1, color: 'rgba(255,139,53,0)' // 100% 处的颜色
                        }],
                        global: false // 缺省为 false
                    }];
                    if (Number(params.name.substring(11, 16).substr(0, 2)) >= 0 && Number(params.name.substring(11, 16).substr(0, 2)) < 8) {//谷
                        return colorList[0];
                    } else if ((Number(params.name.substring(11, 16).substr(0, 2)) >= 12 && Number(params.name.substring(11, 16).substr(0, 2)) < 17) || (Number(params.name.substring(11, 16).substr(0, 2)) >= 21)) {
                        return colorList[1];
                    } else {
                        return colorList[2]
                    }
                }
            }
        }
    }]
};
var option_line3 = {//实时功率
    color: '#718BF3',
    tooltip: {
        trigger: 'axis',
        axisPointer: {
            type: 'line',
            lineStyle: {
                type: 'dashed',
                color: '#30DA9B'
            }
        },
        backgroundColor: 'rgba(39, 71, 105, 0.7)'
    },
    grid: {
        top: 15,
        left: 15,
        right: 18,
        bottom: 0,
        containLabel: true
    },
    xAxis: {
        type: 'category',
        boundaryGap: false,
        axisLine: {
            lineStyle: {
                color: 'rgba(209, 230, 249, 0.7)'
            }
        },
        axisLabel: {
            color: 'rgba(209, 230, 249, 0.7)'
        },
        axisTick: {
            lineStyle: {
                color: 'rgba(209, 230, 249, 0.7)'
            }
        },
        splitLine: {
            show: false
        }
    },
    yAxis: {
        type: 'value',
        axisLine: {
            show: false
        },
        axisLabel: {
            color: '#fff'
        },
        axisTick: {
            show: false
        },
        splitLine: {
            lineStyle: {
                color: ['rgba(22, 126, 226, 0.2)'],
                type: 'dashed'
            }
        }
    },
    series: [{
        name: '功率',
        type: 'line',
        showSymbol: false,
        symbolSize: 1,
        smooth: true,
        lineStyle: {
            width: 2,
            shadowBlur: 6,
            shadowColor: 'rgba(80,115,255,0.74)'
        },
    }]
};
var option_radar = {//用电分析
    title: {
        text: '',
        bottom: 0,
        left: 'center',
        textStyle: {
            color: '#fff',
            fontSize: 12,
            fontWeight: 400
        }
    },
    color: '#1890FF',
    tooltip: {
        backgroundColor: 'rgba(39, 71, 105, 0.7)'
    },
    radar: {
        name: {
            textStyle: {
                color: '#fff',
                lineHeight: 14
            }
        },
        center: ['50%', '57%'],
        radius: '70%',
        indicator: [
            {name: '电压偏差', max: 100},
            {name: '频率\n偏差', max: 100},
            {name: '三相不平衡', max: 100},
            {name: '负载率', max: 100},
            {name: '功率\n因数', max: 100}
        ],
        axisLine: {
            lineStyle: {
                color: 'rgba(209, 230, 249, 0.7)'
            }
        },
        splitLine: {
            lineStyle: {
                color: ['#707070']
            }
        },
        splitArea: {
            areaStyle: {
                color: ['rgba(250,250,250,0.1)', 'rgba(200,200,200,0.1)']
            }
        }
    },
    series: [{
        name: '用电分析',
        type: 'radar',
        showSymbol: false,
        areaStyle: {
            color: 'rgba(13, 98, 177, 0.3)'
        },
        lineStyle: {
            color: '#1890FF',
            width: 2
        },
        label: {
            //show: true,
            formatter: '{c}'
        }
        /*,
        data: [{
            value: [95, 100, 88, 98, 90]
        }]
        */
    }]
};
var option_bar3 = {//modal用电分析
    legend: {
        textStyle: {
            color: '#fff'
        }
    },
    color: [{
        type: 'linear',
        x: 0,
        y: 0,
        x2: 0,
        y2: 1,
        colorStops: [{
            offset: 0, color: '#C6F694' // 0% 处的颜色
        }, {
            offset: 1, color: 'rgba(3,3,3,0)' // 100% 处的颜色
        }]
    }, {
        type: 'linear',
        x: 0,
        y: 0,
        x2: 0,
        y2: 1,
        colorStops: [{
            offset: 0, color: '#8F74FF' // 0% 处的颜色
        }, {
            offset: 1, color: 'rgba(3,3,3,0)' // 100% 处的颜色
        }]
    }, {
        type: 'linear',
        x: 0,
        y: 0,
        x2: 0,
        y2: 1,
        colorStops: [{
            offset: 0, color: '#FFB214' // 0% 处的颜色
        }, {
            offset: 1, color: 'rgba(3,3,3,0)' // 100% 处的颜色
        }]
    }, {
        type: 'linear',
        x: 0,
        y: 0,
        x2: 0,
        y2: 1,
        colorStops: [{
            offset: 0, color: '#1362FF' // 0% 处的颜色
        }, {
            offset: 1, color: 'rgba(0,0,0,0)' // 100% 处的颜色
        }]
    }, {
        type: 'linear',
        x: 0,
        y: 0,
        x2: 0,
        y2: 1,
        colorStops: [{
            offset: 0, color: '#FB7D1B' // 0% 处的颜色
        }, {
            offset: 1, color: 'rgba(3,3,3,0)' // 100% 处的颜色
        }]
    }, '#0096FF'],
    tooltip: {
        trigger: 'axis',
        axisPointer: {
            type: 'line',
            lineStyle: {
                type: 'dashed',
                color: '#aaa'
            }
        }
    },
    grid: {
        top: 45,
        left: 10,
        right: 10,
        bottom: 25,
        containLabel: true
    },
    xAxis: {
        type: 'category',
        axisLine: {
            lineStyle: {
                color: 'rgba(209, 230, 249, 0.7)'
            }
        },
        axisLabel: {
            color: 'rgba(209, 230, 249, 0.7)'
        },
        axisTick: {
            lineStyle: {
                color: 'rgba(209, 230, 249, 0.7)'
            }
        },
        splitLine: {
            show: false
        }
    },
    yAxis: {
        type: 'value',
        axisLine: {
            show: false
        },
        axisLabel: {
            color: '#fff'
        },
        axisTick: {
            show: false
        },
        splitLine: {
            lineStyle: {
                color: ['rgba(22, 126, 226, 0.2)'],
                type: 'dashed'
            }
        }
    },
    dataZoom: [{
        type: 'slider',
        startValue: arrLength - 7,
        endValue: arrLength - 1,
        bottom: 0,
        top: 380,
        borderColor: {//框颜色
            type: 'linear',
            x: 0,
            y: 0,
            x2: 1,
            y2: 0,
            colorStops: [{
                offset: 0, color: '#032668'
            }, {
                offset: 0.5, color: '#0096ff'
            }, {
                offset: 1, color: '#032668'
            }]
        },
        handleStyle: {
            color: '#0096ff',//手柄颜色
        },
        fillerColor: 'rgba(11, 63, 99, 0.7)',//选中区域颜色
        textStyle: {
            color: '#12B0DE'
        },
        dataBackground: {
            lineStyle: {
                color: '#0096ff',
                opacity: 0.4
            },
            areaStyle: {
                color: '#0e3058'
            }
        }
    }],
    series: [{
        name: '电压偏差',
        type: 'bar',
        itemStyle: {
            barBorderRadius: [13, 13, 0, 0]
        }
    }, {
        name: '功率因数',
        type: 'bar',
        itemStyle: {
            barBorderRadius: [13, 13, 0, 0]
        }
    }, {
        name: '频率偏差',
        type: 'bar',
        itemStyle: {
            barBorderRadius: [13, 13, 0, 0]
        }
    }, {
        name: '三相不平衡',
        type: 'bar',
        itemStyle: {
            barBorderRadius: [13, 13, 0, 0]
        }
    }, {
        name: '负载率',
        type: 'bar',
        itemStyle: {
            barBorderRadius: [13, 13, 0, 0]
        }
    }, {
        name: '健康指数',
        type: 'line',
        symbolSize: 4
    }]
};
var option_bar4 = {//谐波畸变率
    tooltip: {
        trigger: 'axis',
        axisPointer: {
            type: 'shadow',
            shadowStyle: {
                color: 'rgba(59, 85, 159, 0.3)'
            }
        },
        backgroundColor: 'rgba(39, 71, 105, 0.7)'
    },
    legend: {
        bottom: 0,
        icon: 'circle',
        itemWidth: 10,
        itemHeight: 10,
        itemGap: 24,
        textStyle: {
            color: '#fff',
            fontSize: 14
        }
    },
    grid: {
        top: 30,
        left: 0,
        right: 5,
        bottom: 30,
        containLabel: true
    },
    xAxis: {
        type: 'category',
        axisLine: {
            lineStyle: {
                color: 'rgba(209, 230, 249, 0.7)'
            }
        },
        axisLabel: {
            color: 'rgba(209, 230, 249, 0.7)'
        },
        axisTick: {
            lineStyle: {
                color: 'rgba(209, 230, 249, 0.7)'
            }
        },
        splitLine: {
            show: false
        }
    },
    yAxis: {
        type: 'value',
        name: '%',
        nameTextStyle: {
            color: '#fff'
        },
        axisLine: {
            show: false
        },
        axisLabel: {
            color: '#fff'
        },
        axisTick: {
            show: false
        },
        splitLine: {
            lineStyle: {
                color: ['rgba(22, 126, 226, 0.2)'],
                type: 'dashed'
            }
        }
    },
    dataset: {
        source: []
    },
    series: []
};
var harmonic_single = [{
    name: '谐波畸变率',
    type: 'bar',
    itemStyle: {
        barBorderRadius: [3, 3, 0, 0],
        color: new echarts.graphic.LinearGradient(
            0, 0, 0, 1,
            [
                {offset: 0, color: 'rgba(131,208,239,1)'},
                {offset: 1, color: 'rgba(131,208,239,0)'}
            ]
        )
    }
}];
var harmonic_multi = [{
    name: 'A相',
    type: 'bar',
    itemStyle: {
        barBorderRadius: [3, 3, 0, 0],
        color: new echarts.graphic.LinearGradient(
            0, 0, 0, 1,
            [
                {offset: 0, color: 'rgba(250,212,136,1)'},
                {offset: 1, color: 'rgba(250,212,136,0)'}
            ]
        )
    }
}, {
    name: 'B相',
    type: 'bar',
    itemStyle: {
        barBorderRadius: [3, 3, 0, 0],
        color: new echarts.graphic.LinearGradient(
            0, 0, 0, 1,
            [
                {offset: 0, color: 'rgba(96,238,180,1)'},
                {offset: 1, color: 'rgba(96,238,180,0)'}
            ]
        )
    },
}, {
    name: 'C相',
    type: 'bar',
    itemStyle: {
        barBorderRadius: [3, 3, 0, 0],
        color: new echarts.graphic.LinearGradient(
            0, 0, 0, 1,
            [
                {offset: 0, color: 'rgba(249,89,89,1)'},
                {offset: 1, color: 'rgba(249,89,89,0)'}
            ]
        )
    },
}];

function buildTable(table, titleList, labelList, dataList, deal) {
    $(table).empty();
    var thead = createElement('thead', table, null, null);
    var theadTr = createElement('tr', thead, null, null);
    var tbody = createElement('tbody', table, null, null);
    titleList.map(function (title) {
        createElement('th', theadTr, title, null);
    });
    if (dataList.length > 0) {
        dataList.map(function (item) {
            var tr = createElement('tr', tbody, null, null);
            labelList.map(function (label) {
                var td = createElement('td', tr, item[label], null);
                if (deal) {
                    deal(td, label, item);
                }
            });
        });
    } else {
        var tr = createElement('tr', tbody, null, null);
        var td = createElement('td', tr, '无报警数据', null);
        $(td).css('text-align', 'center');
        $(td).attr('colspan', titleList.length);
        $(td).addClass('wsj');
    }
}